package com.auto.survey.activity.monitoring.modle

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.auto.survey.activity.monitoring.entity.MonitorStauts
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancel
import kotlinx.coroutines.launch

class CreateStationViewModle: ViewModel() {

    // 使用协程作用域处理数据库操作
    private val viewModelScope = CoroutineScope(Dispatchers.IO + SupervisorJob())

    val state = MutableLiveData<MonitorStauts>()
    val mirrorType = MutableLiveData<String>()
    val measureModle = MutableLiveData<String>()


    fun updateState(stauts:MonitorStauts) {
        state.postValue(stauts)
    }


    fun updateMirrorType(type:String){
        mirrorType.postValue(type)
    }

    fun updateMeasureModle(modle:String){
        measureModle.postValue(modle)
    }

    // ViewModel 销毁时取消协程
    override fun onCleared() {
        super.onCleared()
        viewModelScope.cancel()
    }
}